package com.r_z.service.impl;

import com.r_z.entity.UserRole;
import com.r_z.entity.Users;
import com.r_z.mapper.UsersMapper;
import com.r_z.service.UsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 梁俊
 * @date 2023/5/29
 * &@version 1.0
 */
@Service
public class UsersServiceImpl implements UsersService {

    @Resource
    public UsersMapper usersMapper;

    @Override
    public Users checkLogin(Users users) {
        return usersMapper.checkLogin(users);
    }

    @Override
    public List<Users> selectLikeUsers(Map map) {
        return usersMapper.selectLikeUsers(map);
    }

    @Override
    public int selectUserNameCount(String userName) {
        return usersMapper.selectUserNameCount(userName);
    }

    @Override
    public int deleteUsers(int userId) {
        return usersMapper.deleteUsers(userId);
    }

    @Override
    public int deleteDuoUsers(String userId) {
        //将id转为数据
        String[] split = userId.split(",");
        //创建存放id的集合
        ArrayList<Object> equityDataIdList = new ArrayList<>();
        for (String id : split) {
            //将id存入集合
            equityDataIdList.add(id);
        }
        return usersMapper.deleteDuoUsers(equityDataIdList);
    }

    @Override
    public Users selectIdUser(int userId) {
        return usersMapper.selectIdUser(userId);
    }

    @Override
    public int updateUsers(Users users) {
        return usersMapper.updateUsers(users);
    }

    @Override
    public int addUsers(Users users) {
        return usersMapper.addUsers(users);
    }

    @Override
    public int updateUserRolew(int userRoleId,String userRoleName) {
        return usersMapper.updateUserRolew(userRoleId,userRoleName);
    }
}

